<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript" src="js/tools.js"></script>
		<style type="text/css">
			*{
				padding: 0;
				margin: 0;
			}
			
			#outer{
				position: relative;
				width: 520px;
				height: 333px;
				background-color: green;
				margin: 50px auto;
				padding: 10px 0;
				overflow: hidden;
			}
			
			#imgList{
				list-style: none;
				
				position: absolute;
			}
			
			#imgList li{
				float: left;
				margin: 0 10px;
			}
			
			#navDiv{
				position: absolute;
				
				bottom: 15px;
			}
			
			#navDiv a{
				float: left;
				width: 15px;
				height: 15px;
				background-color: green;
				margin: 0 5px;
				opacity: 50%;
				/*兼容IE8*/
				filter: alpha(opacity=50);
			}
		</style>
		
		<script type="text/javascript" >
			window.onload = function(){
				//获取imgList元素
				var imgList = document.getElementById("imgList");
				//获取所有的img
				var imgArr = document.getElementsByTagName("img");
				//改变imgList的宽度
				imgList.style.width = 520 * imgArr.length + "px";
				
				//获取navDiv
				var navDiv = document.getElementById("navDiv");
				//获取所有a
				var allA = document.getElementsByTagName("a");
				//获取父元素
				var outer = document.getElementById("outer");
				//改变navDiv的left值
				navDiv.style.left = (outer.offsetWidth - navDiv.offsetWidth) / 2 + "px";
				
				//设置索引
				var index = 0;
				//设置默认圆点的颜色
				allA[index].style.backgroundColor = "black";
				
				for(var i=0; i<allA.length; i++){
					//设置num
					allA[i].num = i;
					//为每个圆点绑定单击响应函数
					allA[i].onclick = function(){
						clearInterval(timer);
						
						index = this.num;
						
						//设置点击后的颜色变化
						setA();
						
						//切换图片
						move(imgList , "left" , -520*index , 20 , function(){
							autoChange();
						});
					};
				}
				
				//图片自动切换
				autoChange();
				
				function setA(){
					//如果到了最后一张图片，则将他设置为第一张
					if(index >= imgArr.length - 1){
						index = 0;
						imgList.style.left = 0;
					}
					//将所有的原点都设置成红色
					for(var i=0; i<allA.length; i++){
						allA[i].style.backgroundColor = "";
					}
					//将选中的圆点设置成黑色
						allA[index].style.backgroundColor = "black";
					
				}
				
				//创建变量timer
				var timer;
				
				function autoChange(){
					//创建定时器
					timer = setInterval(function(){
						//index自增
						index++;
						//设置最大索引值
						index %= imgArr.length;
						//图片切换
						move(imgList , "left" , -520*index , 20 , function(){
							setA();
						});
					},3000);
					
				}
			};
			
		</script>
	</head>
	<body>
		<!--创建外层容器-->
		<div id="outer">
			<!--创建图片列表-->
			<ul id="imgList">
				<li><img src="img/dl.jpg"/></li>
				<li><img src="img/1.jpg"/></li>
				<li><img src="img/2.jpg"/></li>
				<li><img src="img/3.jpg"/></li>
				<li><img src="img/4.jpg"/></li>
				<li><img src="img/5.jpg"/></li>
				<li><img src="img/dl.jpg"/></li>
				
			</ul>
			
			<!--创建小圆点图标-->
			<div id="navDiv">
				<a href="javascript:;"></a>
				<a href="javascript:;"></a>
				<a href="javascript:;"></a>
				<a href="javascript:;"></a>
				<a href="javascript:;"></a>
				<a href="javascript:;"></a>
			</div>
			
		</div>
	</body>
</html>
